package com.chinasofti.list;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class Demo02 {
    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        list.add("a");
        list.add("b");
        list.add("c");
        list.add("d");
        //method1(list);
        //method2(list);
        //method3(list);
        //获取指定位置元素
        String s = list.get(0);
        System.out.println("s = " + s);
        System.out.println(list);
    }

    private static void method3(List<String> list) {
        //修改指定位置的元素，返回修改的元素
        String s = list.set(0, "qqq");
        System.out.println("s = " + s);
        System.out.println(list);
    }

    private static void method2(List<String> list) {
        //删除指定位置的元素，返回被删除的元素；
        String s = list.remove(0);
        System.out.println("s = " + s);
        System.out.println(list);
    }

    private static void method1(List<String> list) {
        list.add(0,"qqq");//在此集合中的指定位置插入指定元素
        System.out.println("list = " + list);
    }
}
